package com.itheima.pojo;

import com.itheima.exception.BusinessException;
import com.itheima.project.Dept;
import com.itheima.project.emp.Emp;
import com.itheima.project.emp.EmpExpr;
import com.itheima.project.classdata.Clazz;
import com.itheima.project.student.Student;

import java.util.List;

public class ProjectUtil {
    public static void checkSpace(Emp emp) {

        if (emp.getUsername().contains(" ")) {
            throw new BusinessException("用户名不能包含空格");
        }
        if (emp.getName().contains(" ")) {
            throw new BusinessException("姓名不能包含空格");
        }


    }

    public static void checkSpace(Dept dept) {

        if (dept.getName().contains(" ")) {
            throw new BusinessException("部门名称不能包含空格");
        }
        if (
                dept.getName().replaceAll("\\s", "").equals("")
        ) {
            throw new BusinessException("部门名称不能为空");
        }

    }

    public static void checkSpace(List<EmpExpr> exprList) {

        for (EmpExpr expr : exprList) {
            if (expr.getCompany().contains(" ") || expr.getJob().contains(" ")) {
                throw new BusinessException("工作经历不能包含空格");
            }
            if (
                    expr.getCompany().replaceAll("\\s", "").equals("") ||
                            expr.getJob().replaceAll("\\s", "").equals("")
            ) {
                throw new BusinessException("工作经历不能为空");
            }
        }

    }

    public static void checkSpace(Clazz clazz) {

        if (clazz.getName().contains(" ")) {
            throw new BusinessException("班级名称不能包含空格");
        }
        if (
                clazz.getName().replaceAll("\\s", "").equals("")
        ) {
            throw new BusinessException("班级名称不能为空");
        }

    }

    public static void checkSpace(Student student) {

        if (
                student.getAddress().replaceAll("\\s", "").equals("")
        ) {
            throw new BusinessException("姓名不能为空格");
        }
        if (
                student.getName().contains(" ")
        ) {
            throw new BusinessException("学号不能包含空格");
        }

    }

    public static void checkSpace(Integer score) {
        if (score == 0) {
            throw new BusinessException("违纪不能扣0分");
        }

        if (!score.toString().matches("-?\\d+")) {
            throw new BusinessException("请正确输入");
        }



    }
}
